"""
Case Type   : GUC参数
Case Name   : 修改参数allocate_mem_cost为其他数据类型，观察预期结果
Create At   : 2021-10-9
Owner       : opentestcase005
Description :
    1.show参数默认值
    2.修改参数默认值为test
Expect      :
    1.参数默认值为0
    2.修改参数默认值为test，合理报错
History     :
    modified by opentestcase013 at 2022-09-14:优化用例，修改合理报错信息
"""

import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node


class Guc(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info('Opengauss_Function_Guc_Parameter_Case1244开始')
        self.dbuser = Node('dbuser')
        self.constant = Constant()
        self.commonsh = CommonSH('PrimaryDbUser')

    def test_guc_parameter(self):
        text = '--step1:show参数默认值;expect:参数默认值0--'
        self.log.info(text)
        sql_cmd = self.commonsh.execut_db_sql(f'show allocate_mem_cost;')
        self.log.info(sql_cmd)
        self.default_value = sql_cmd.splitlines()[2].strip()
        self.log.info(self.default_value)
        error_msg1 = 'ERROR: The parameter "allocate_mem_cost" requires' \
                     ' a numeric value.'

        text = '--step2:修改参数默认值为test--;expect:合理报错--'
        self.log.info(text)
        mod_msg = self.commonsh.execute_gsguc('set',
                                              error_msg1,
                                              'allocate_mem_cost =test')
        self.log.info(mod_msg)
        self.assertTrue(mod_msg, '执行失败:' + text)

    def tearDown(self):
        self.log.info('--无需清理环境--')
        self.log.info('Opengauss_Function_Guc_Parameter_Case1244结束')
